package com.shqcjd.preinstallmobile.ui.adapter;

import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.shqcjd.preinstallmobile.R;
import com.shqcjd.preinstallmobile.model.pojo.IndexBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by sy on 2019/3/15.
 */

public class EqptStateAdapter extends BaseQuickAdapter<IndexBean.EquipmentStateBean,EqptStateAdapter.ViewHolder> {

    public EqptStateAdapter(@Nullable List<IndexBean.EquipmentStateBean> data) {
        super(R.layout.item_eqpt_state, data);
    }

    @Override
    protected void convert(EqptStateAdapter.ViewHolder helper, IndexBean.EquipmentStateBean item) {
        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.ic_default_small)	//加载成功之前占位图
                .error(R.mipmap.ic_default_small)	//加载错误之后的错误图
//                .override(79,73)	//指定图片的尺寸
                .centerCrop();//指定图片的缩放类型为centerCrop （等比例缩放图片，直到图片的宽高都
        Glide.with(mContext)
                .load(item.img)
                .apply(options)
                .into(helper.iv_img);

        helper.tv_name.setText(item.name);
        switch (item.state) {
            case 1:
                helper.tv_eqpt_state.setText("巡检已完成");
                helper.tv_eqpt_state.setTextColor(ContextCompat.getColor(mContext,R.color.equipment_font));
                break;
            case 0:
                helper.tv_eqpt_state.setText("巡检未完成");
                helper.tv_eqpt_state.setTextColor(ContextCompat.getColor(mContext,R.color.equipment_inspection_red));
                break;
        }
        if (item.exception > 0) {
            helper.tv_exception.setText(item.exception+"");
            helper.tv_exception.setTextColor(ContextCompat.getColor(mContext, R.color.equipment_inspection_red));
        } else {
            helper.tv_exception.setText(item.exception+"");
            helper.tv_exception.setTextColor(ContextCompat.getColor(mContext, R.color.equipment_font));
        }


    }

    class ViewHolder extends BaseViewHolder {
        @BindView(R.id.iv_img)
        ImageView iv_img;
        @BindView(R.id.tv_name)
        TextView tv_name;
        @BindView(R.id.tv_eqpt_state)
        TextView tv_eqpt_state;
        @BindView(R.id.tv_exception)
        TextView tv_exception;
        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
